//
//  AddYunDanTwoCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/9/17.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "AddYunDanTwoCell.h"

@interface AddYunDanTwoCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *numLab;
@property (nonatomic, strong) UIButton *editBtn;
@property (nonatomic, strong) UIButton *selectBtn;

@end

@implementation AddYunDanTwoCell

+ (instancetype)AddYunDanTwoCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"AddYunDanTwoCell";
    AddYunDanTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[AddYunDanTwoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 10, ScreenW - 30, 114)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.editBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, self.bgView.nim_height - 15 - 42, self.bgView.nim_width - 30, 42)];
        self.editBtn.backgroundColor = HexColorA(0x3D68EB, 0.06);
        self.editBtn.layer.masksToBounds = YES;
        self.editBtn.layer.cornerRadius = 4;
        [self.editBtn setTitle:@"编辑提货清单" forState:0];
        [self.editBtn setTitleColor:HexColor(0x3D68EB) forState:0];
        self.editBtn.titleLabel.font = BoldFontOfSize(16);
        [self.editBtn setImage:[UIImage imageNamed:@"icon_add_yundan_edit"] forState:0];
        [self.editBtn addTarget:self action:@selector(editClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.editBtn];
        
        self.selectBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.nim_width - 15 - 23, (self.editBtn.nim_top - 23) * 0.5, 23, 23)];
        [self.selectBtn addTarget:self action:@selector(selectClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.selectBtn];
        
        self.numLab = [UILabel new];
        self.numLab.nim_left = 15;
        self.numLab.nim_width = self.selectBtn.nim_left - 15 - 15;
        self.numLab.nim_height = 17;
        self.numLab.nim_centerY = self.selectBtn.nim_centerY;
        self.numLab.textColor = HexColor(0x2B2C44);
        self.numLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.numLab];
        
        self.height = self.bgView.nim_bottom;
    }
    return self;
}

- (void)selectClick {
    if (self.selectBlock) {
        self.selectBlock();
    }
}

- (void)editClick {
    if (self.editBlock) {
        self.editBlock();
    }
}

-(void)setModel:(AddYunDanTiHuoBillModel *)model {
    _model = model;
    self.numLab.text = [NSString stringWithFormat:@"提货单号：%@",model.serial_num];
    [self.selectBtn setImage:[UIImage imageNamed:model.selected ? @"icon_add_yundan_select_yes" : @"icon_add_yundan_select_no"] forState:0];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
